package com.wzy.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.wzy.dao.BaseDao;
import com.wzy.dao.PetDao;
import com.wzy.entity.Pet;

public class PetDaoImpl extends BaseDao implements PetDao{

	@Override
	public List<Pet> getAllPet() {
		List<Pet> list = new ArrayList<Pet>();
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			conn = super.getConnection();
			
			String sql = "select * from pet";
			pstmt = conn.prepareStatement(sql);
			
			rs = pstmt.executeQuery();
			
			while (rs.next()) {
				Pet pet = new Pet();
				pet.setId(rs.getLong("id"));
				pet.setName(rs.getString("name"));
				pet.setTypeName(rs.getString("typename"));
				
				list.add(pet);
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			super.closeAll(conn, pstmt, rs);
		}
		
		return list;
	}

}
